home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -serious- / programming / other / littelcomp / r5 / lc / examples / ptrs.l < prev    next >
Text File  |  2000-02-28  |  2KB  |  67 lines

  1. ;//
  2.  
  3. ; L v0.17 - make a little library and use some ptrs -
  4.  
  5. ; make it a library ***********************************
  6.  
  7. #mode LIBRARY 37 1 "ptrs.library" "ptrs.library by me 99"
  8. #link library.lib                ; link in preassembled library code
  9. #fdef bubblesort2                ; our two library functions ..
  10. #fdef fill_longarray_with_words
  11. #endfdef
  12.  
  13. ; its was that simple *********************************
  14.  
  15. #equ Useful    10      ; define some constants
  16. #equ NotUseful 0
  17. #equ LongSize  4
  18. #equ WordSize  2
  19.  
  20.     ; remember : youre only allowed to use d0-d5/a0-a3 ! //
  21.     ; if itsnot a special case like, just before calling or doprocing //
  22.  
  23. proc bubblesort2     ; array of long -> d0, len -> d1
  24.    var end           ; declare a variabel (local)
  25.    codestart
  26.    copy d0       end
  27.    add  d1       end
  28.    dec  end      LongSize
  29.    repeat
  30.       copy NotUseful d2
  31.       copy d0 a0
  32.       repeat
  33.          if a0[] > a0[].LongSize      ; gt : greater then
  34.             swap a0[]   a0[].LongSize ; aaah..mmm.. swap.. :)
  35.             copy Useful d2
  36.          endif
  37.          inc a0 LongSize
  38.       endrepeat a0 = end
  39.    endrepeat d2 = NotUseful
  40. endproc
  41.  
  42.    ; note : for speed reasons we use ax and dx registers here..  //
  43.    ; but we could have done it in exactly the same way usin just //
  44.    ; local vars, they can also work as ptrs : myvar[].           //
  45.    ; remeber!  : you are only allowed to use d0-d5, a0-a3!       //
  46.    ; but hey.. variables arent that slow anyway ..               //
  47.  
  48.    ; another example.. //
  49.  
  50. proc fill_longarray_with_words ; longarray -> d0, wordarray -> d1, nrofwords -> d2
  51.    var larray  warray  len         ; local vars
  52.    codestart
  53.    copy d0 larray      ; copying some regs to som vars..
  54.    copy d1 warray
  55.    copy d2 len
  56.  
  57.    while len > 0                  ; while len > 0
  58.       copy warray[W]  larray[L]
  59.       inc warray      WordSize    ; add 2 to warray
  60.       inc larray      LongSize    ; add 4 to larray
  61.       dec len         ;sub 1 from len
  62.    endwhile
  63. endproc
  64.  
  65. end
  66.   
  67.